package com.emspost.utils;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @auth Pzz
 * @date 2023/9/14 11:11
 */

public class DateUtil {

    private static String PATTERN_YYYY_MM_DD="yyyyMMdd";

    /**
     * 获取时间字符串
     * @param amount
     * @return
     */
    public static String getStrDate(int amount){
        SimpleDateFormat sdf = new SimpleDateFormat(PATTERN_YYYY_MM_DD);
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH, amount);
        String dateStr = sdf.format(cal.getTime());
        return dateStr;
    }


    /**
     * 获取时间列表
     * @param startTime
     * @param endTime
     * @return
     */
    public static List<Map<String,Object>> getDateList(String startTime, String endTime,String tableName) {
        List<Map<String,Object>> mapList = new ArrayList<>();
        try{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            Date startDate = sdf.parse(startTime);
            Calendar cal = Calendar.getInstance();
            cal.setTime(startDate);
            int a= 0;
            for (int i = 0; i < 999; i++) {
                Map<String, Object> map = new HashMap<>(4);
                map.put("tableName",tableName);
                a = 1;
                String settleDate = sdf.format(cal.getTime());
                map.put("startTime",settleDate);
                Date endTime1 = sdf.parse(settleDate);
                cal.setTime(endTime1);
                cal.add(Calendar.DAY_OF_MONTH, a);
                String endTime2 = sdf.format(cal.getTime());
                map.put("endTime",endTime2 );
                if(settleDate.equals(endTime)) {
                    break;
                }
                System.out.println(map);
                mapList.add(map);
            }
        } catch (ParseException e){
            e.printStackTrace();
        }
        return mapList;
    }





    /**
     *
     * @param list
     * @return
     */
    public static List<Map<String,Object>> getAppointDateList(List<String> list ) {
        List<Map<String,Object>> mapList = new ArrayList<>();
        try{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            for (String handleDte: list) {
                Map<String, Object> map = new HashMap<>(4);
                Date startDate = sdf.parse(handleDte);
                Calendar cal = Calendar.getInstance();
                cal.setTime(startDate);
                String settleDate = sdf.format(cal.getTime());
                map.put("startTime",settleDate);
                Date endTime1 = sdf.parse(settleDate);
                cal.setTime(endTime1);
                cal.add(Calendar.DAY_OF_MONTH, 1);
                String endTime2 = sdf.format(cal.getTime());
                map.put("endTime",endTime2 );
                System.out.println(map);
                mapList.add(map);
            }
        } catch (ParseException e){
            e.printStackTrace();
        }
        return mapList;
    }

    public static void main(String[] args) throws ParseException {
        // List<Map<String,Object>> dateList = getDateList("20210901", "20210915","");
        List<Map<String, Object>> dateList = getAppointDateList(gethandleData());
        System.out.println(dateList);
        System.out.println(dateList.size());
    }
    public static List<String> gethandleData(){
        String[] data = {
                "20230908",
                "20230909",
                "20230910",
                "20230912",
                "20230913",
                "20230914",
                "20230915",
                "20230916",
                "20230917",
                "20230918",
                "20230919",
                "20230920",
                "20230921",
                "20230922",
                "20230923",
                "20230924",
                "20230927",
                "20230928",
                "20230929",
                "20231002",
                "20231003",
                "20231004",
                "20231005",
                "20231007",
                "20231008",
                "20231009",
                "20231010",
                "20231013",
                "20231014",
                "20231015",
                "20231016",
                "20231019",
                "20231020",
                "20231021",
                "20231023",
                "20231024",
                "20231025",
                "20231026",
                "20231028",
                "20231029",
                "20231030",
                "20231031",
                "20231102",
                "20231104",
                "20231105",
                "20231106",
                "20231107",
                "20231109",
                "20231110",
                "20231111",
                "20231112",
                "20231114",
                "20231116",
                "20231117",
                "20231119",
                "20231120",
                "20231121",
                "20231123",
                "20231124",
                "20231125",
                "20231126",
                "20231128",
                "20231129",
                "20231130",
                "20231201",
                "20231203",
                "20231204",
                "20231205",
                "20231206",
                "20231207",
                "20231208",
                "20231209",
                "20231210",
                "20231211",
                "20231212",
                "20231214",
                "20231215",
                "20231216",
                "20231220",
                "20231221",
                "20240121",
                "20240122",
                "20240124",
                "20240125",
                "20240126",
                "20240127",
                "20240128",
                "20240129",
                "20240201",
                "20240202",
                "20240203",
                "20240204",
                "20240205",
                "20240207",
                "20240208",
                "20240209",
                "20240211",
                "20240213",
                "20240214",
                "20240215",
                "20240217",
                "20240218",
                "20240219",
                "20240220",
                "20240222",
                "20240224",
                "20240225",
                "20240226",
                "20240227",
                "20240229",
                "20240301",
                "20240303",
                "20240304",
                "20240306",
                "20240308",
                "20240309",
                "20240310",
                "20240311",
                "20240312",
                "20240313",
                "20240316",
                "20240317",
                "20240318",
                "20240319",
                "20240321",
                "20240323",
                "20240325",
                "20240326",
                "20240327",
                "20240328",
                "20240329",
                "20240330",
                "20240331",
                "20240402",
                "20240403",
                "20240404",
                "20240405",
                "20240407",
                "20240409",
                "20240411",
                "20240412",
                "20240413",
                "20240414",
                "20240415",
                "20240416",
                "20240419",
                "20240420",
                "20240421",
                "20240422",
                "20240423",
                "20240425",
                "20240426",
                "20240427",
                "20240428",
                "20240430",
                "20240501",
                "20240502",
                "20240503",
                "20240505",
                "20240506",
                "20240508",
                "20240511",
                "20240512",
                "20240513",
                "20240514",
                "20240516",
                "20240518",
                "20240520",
                "20240521",
                "20240523",
                "20240524",
                "20240525",
                "20240526",
                "20240528",
                "20240529",
                "20240530",
                "20240531",
                "20240601",
                "20240604",
                "20240605",
                "20240606",
                "20240607",
                "20240609",
                "20240610",
                "20240611",
                "20240612",
                "20240613",
                "20240614",
                "20240616",
                "20240619",
                "20240620",
                "20240621",
                "20240622",
                "20240623",
                "20240624",
                "20240625",
                "20240627",
                "20240628",
                "20240629"
        };
        List<String> list = Arrays.asList(data);
        return list;
    }






}
